package com.xxd.spring.boot.demo.lihonghai.controller;


import com.xxd.spring.boot.demo.lihonghai.Eeception.MyException;
import com.xxd.spring.boot.demo.lihonghai.Result;
import com.xxd.spring.boot.demo.lihonghai.constant.ConstantData;
import com.xxd.spring.boot.demo.lihonghai.entity.User;
import com.xxd.spring.boot.demo.lihonghai.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/regsit")
    public Result regsit(@RequestBody User user) throws MyException{
        userService.regsit(user) ;
        return new Result().success();
    }

@RequestMapping("/login")
    public Result login(@RequestBody User user) throws MyException{
        User dbUser=userService.login(user.getUsername(),user.getPassword());
        String uuid=UUID.randomUUID().toString();
        ConstantData.userMap.put(uuid,dbUser);
        return new Result().success().setData(uuid);
    }
}

